<template>
  姓名：<input v-model="name">
  年龄：<input v-model="age">
  电话：<input v-model="tel">
  <button @click="baocun">暂时保存</button>
  <button @click="baocun">立即提交</button>
</template>

<script setup lang="ts">


</script>
<script setup lang="ts">
import { useRoute } from 'vue-router';
import { computed, ref, onMounted } from "vue";
import router from "../../Router";
import type {Numeric} from "vant/es/utils";
import axios from 'axios'
import { useUserStore } from '../../Store/modules/userinfo/UserInfo.ts'

const userInfo = useUserStore()
const route = useRoute();

// 从Pinia加载保存的数据
const loadSavedData = () => {
  if (userInfo.tempMeetingRecord.meetingType) {
    meetingType.value = userInfo.tempMeetingRecord.meetingType
    pickerValue_meetingType.value = [userInfo.tempMeetingRecord.meetingTypeValue]
  }
  if (userInfo.tempMeetingRecord.date) {
    date_value.value = userInfo.tempMeetingRecord.date
  }
  if (userInfo.tempMeetingRecord.time) {
    time_value.value = userInfo.tempMeetingRecord.time
  }
  if (userInfo.tempMeetingRecord.content) {
    meetingContent.value = userInfo.tempMeetingRecord.content
  }
  if (userInfo.tempMeetingRecord.files && userInfo.tempMeetingRecord.files.length > 0) {
    fileList.value = userInfo.tempMeetingRecord.files
  }
}

// 组件挂载时加载保存的数据
onMounted(() => {
  loadSavedData()
})

const meetingContent = ref("")
const title = computed(() => route.meta.title || '未知页面');
const fileList = ref([]);

const meetingType_list = [
  { text: '学业指导', value: 3 },
  { text: '组会', value: 2 },
  { text: '班会', value: 1 },
];
const meetingType = ref('');
const showPicker1 = ref(false);
const pickerValue_meetingType = ref<Numeric[]>([]);
const onConfirm_meetingType = ({ selectedValues, selectedOptions }) => {
  showPicker1.value = false;
  pickerValue_meetingType.value = selectedValues;
  meetingType.value = selectedOptions[0].text;
};

// 当前日期
const currentDate = ref(['2025', '04', '05']);
const minDate = new Date(2020, 0, 1);
const maxDate = new Date(2099, 12, 31);
const date_value = ref('');
const showPicker3 = ref(false);

// 当前时间
const time_value = ref('');
const showPicker4 = ref(false);
const currentTime = ref(['12', '00']);
const formatter = (type, option) => {
  if (type === 'hour') {
    option.text += '时';
  }
  if (type === 'minute') {
    option.text += '分';
  }
  return option;
};

// 设置当前日期
const setCurrentDate = () => {
  const now = new Date();
  currentDate.value = [
    String(now.getFullYear()),
    String(now.getMonth() + 1).padStart(2, '0'),
    String(now.getDate()).padStart(2, '0')
  ];
};

// 设置当前时间
const setCurrentTime = () => {
  const now = new Date();
  currentTime.value = [
    String(now.getHours()).padStart(2, '0'),
    String(now.getMinutes()).padStart(2, '0')
  ];
};

const onConfirmDate = ({ selectedValues }) => {
  showPicker3.value = false;
  date_value.value = selectedValues[0] + "-" + selectedValues[1] + "-" + selectedValues[2];
};

const onConfirmTime = ({ selectedValues }) => {
  showPicker4.value = false;
  time_value.value = selectedValues[0] + ":" + selectedValues[1];
};

// 保存数据到Pinia
const saveToPinia = () => {
  userInfo.tempMeetingRecord = {
    meetingType: meetingType.value,
    meetingTypeValue: pickerValue_meetingType.value[0] || null,
    date: date_value.value,
    time: time_value.value,
    content: meetingContent.value,
    files: [...fileList.value] // 复制数组避免引用问题
  }
}

// 暂时保存按钮点击事件
function xq_zsbc(){
  if (meetingType.value || date_value.value || time_value.value || meetingContent.value || fileList.value.length > 0) {
    saveToPinia()
    // 可以添加一个提示告诉用户已保存
    alert('会议记录已暂时保存')
  } else {
    alert('没有内容需要保存')
  }
}

async function xq_submit(){
  // 提交逻辑...
}
</script>
<style scoped>

</style>
